import 'package:flutter/cupertino.dart';

/// 缺省页显示
class StatusWidget extends StatefulWidget {
  final StatusType type;

  final Widget body;

  final Widget? error;

  final Widget? empty;

  final Widget? loading;

  const StatusWidget({super.key, required this.type, required this.body, this.loading, this.error, this.empty});

  @override
  State<StatusWidget> createState() => _StatusWidgetState();
}

class _StatusWidgetState extends State<StatusWidget> {
  @override
  Widget build(BuildContext context) {
    if (widget.type == StatusType.normal) {
      return widget.body;
    } else if (widget.type == StatusType.loading) {
      return widget.loading ?? widget.body;
    } else if (widget.type == StatusType.error) {
      return widget.error ?? widget.body;
    } else if (widget.type == StatusType.empty) {
      return widget.empty ?? widget.body;
    }

    return widget.body;
  }
}

enum StatusType { empty, error, normal, loading }
